#查找一个文件中最长的行，输出长度


import string
import random

# #生成一个大文件
with open('big.txt','a+',encoding='utf-8') as f:
    for i in range(100000):
        f.write("".join(random.sample(string.digits+'\n[];.,/!@#*#&^%$#+_)(#()*&/*-.,.'+string.ascii_letters,random.randint(1,50))))



def func1():
    with open('big.txt','r+',encoding='utf-8') as fp:
        allLines = {line.strip():len(line) for line in fp}
        # print(dict(sorted(allLines.items(),key=lambda x:x[1])))
        Long_line_count=0
        Long_line=''
        for line in allLines:
            if len(line) > Long_line_count:
                Long_line_count=len(line)
                Long_line=line
                yield Long_line

a=func1()
for line in a:
    pass
print(f'最长的行包含的字符有{len(line)}个！')
print(f'且该行是：{line}')
